//
//  AddRecruitViewController.m
//  SafeFoodManagerDemo
//
//  Created by ios-1 on 2018/3/5.
//  Copyright © 2018年 bob. All rights reserved.
//

#import "AddRecruitViewController.h"
#import "LoginStatuesModel.h"
#import "RegisterShopModel.h"
#import "RSTableHeadView.h"
#import "RegisterSingleTableViewCell.h"
#import "RegisterPopTableViewCell.h"
#import "RegisterMorePicTableViewCell.h"
#import "RegisterMoreTextTableViewCell.h"
#import "RegisterSpicTableViewCell.h"
#import "RegisterTagsTableViewCell.h"
#import "ChooseView.h"
#import "DatePickView.h"
#import "ScanCodeTableViewCell.h"
#import "ScanPhotoViewController.h"
@interface AddRecruitViewController ()<UITableViewDelegate,UITableViewDataSource,UITextViewDelegate>
@property(nonatomic,strong)TB_TableView *RegisterTableView;
@property(nonatomic,strong)HXTagsView *tagsView;
@property(nonatomic,strong)NSMutableArray *tagstitles;
@property(nonatomic,strong)RegisterShopModel *ShopModel;

@property(nonatomic,copy)NSString*headimage;

@property(nonatomic,strong)UIButton *ProvideBtn;

@end

@implementation AddRecruitViewController
{
    CGFloat _specTagViewHeigh;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.isHidenKeyToolBar=NO;
    
    self.isScanphotos=NO;//有预览图片功能
    
    [self.view addSubview:self.RegisterTableView];
    
    [self loadDates];
}

-(UIButton*)ProvideBtn
{
    if (!_ProvideBtn) {
        
        _ProvideBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        
        if (kDevice_Is_iPhoneX) {
            
            _ProvideBtn.frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64-IPhoneXTableHeight, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
            
        }else{
            
            _ProvideBtn.frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
        }
        [_ProvideBtn setTitle:self.BtnStr forState:UIControlStateNormal];
        
        _ProvideBtn.titleLabel.font=[UIFont systemFontOfSize:21];
        
        [_ProvideBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        [_ProvideBtn addTarget:self action:@selector(GotoOption:) forControlEvents:UIControlEventTouchUpInside];
        
        [_ProvideBtn setBackgroundColor:TBColorProvideBtnbg];
        
        
    }
    
    return _ProvideBtn;
}

-(void)viewDidDisappear:(BOOL)animated
{
    self.isHidenKeyToolBar=YES;
    
}

#pragma mark ****************网络请求*****************
-(void)loadDates
{
    
    [self showLoadingAnimation];
    
    BaseReqApi *api=[[BaseReqApi alloc]initWithRequestUrl:self.requrl andrequestTime:5 andParams: self.Reqmodel.mj_keyValues andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:NO];
    
    [api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
        
        [self stopLoadingAnimation];
        
        self.ShopModel=[RegisterShopModel mj_objectWithKeyValues:responseObject];
        
        if (responseStatus==1) {
            
            //请求成功
            if (self.ShopModel.data.count==0) {
                
                self.Type=TBNODateType;
                
            }else{
                
                [self getTagsViewHeigh];
                
                [self.RegisterTableView reloadData];
                
                [self.view addSubview:self.ProvideBtn];
            }
        }else if (responseStatus==0||responseStatus==2)
        {
            [MBProgressHUD showErrorMessage:message];
            
            self.Type=TBReqFalie;
            
        }else{
            //404需要重新登录了
            
            [UIAlertView bk_showAlertViewWithTitle:message message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                
                if (buttonIndex==1) {
                    
                    [self GotoLoginVC];
                }
                
            }];
            
        }
        
    }];
}

- (void)submitInfoHttp
{
    [self showLoadingAnimation];
    NSDictionary *params = [NSMutableDictionary dictionary];
    NSString* shopId=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shopId]];
    
    [params setValue:shopId forKey:@"shopId"];
    [params setValue:@"" forKey:@"postData"];
    
    BaseReqApi *api=[[BaseReqApi alloc]initWithRequestUrl:@"/index.php/FoodCheckApi/postAdd.json" andrequestTime:5 andParams:params andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:YES];
    
    [api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
        
        [self stopLoadingAnimation];
        
        self.ShopModel=[RegisterShopModel mj_objectWithKeyValues:responseObject];
        
        if (responseStatus==1) {
            //请求成功
            
        }else if (responseStatus==0||responseStatus==2)
        {
            [MBProgressHUD showErrorMessage:message];
            
            self.Type=TBReqFalie;
            
        }else{
            //404需要重新登录了
            
            [UIAlertView bk_showAlertViewWithTitle:message message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                
                if (buttonIndex==1) {
                    
                    [self GotoLoginVC];
                }
                
            }];
            
        }
        
    }];
    
}

-(TB_TableView*)RegisterTableView
{
    if (!_RegisterTableView) {
        
        CGRect frame;
        
        if (kDevice_Is_iPhoneX) {
            
            frame=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-44*SCREEN_WIDTH/320-IPhoneXTableHeight);
            
        }else{
            
            frame=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-44*SCREEN_WIDTH/320);
            
        }
        
        _RegisterTableView=[[TB_TableView alloc]initWithFrame:frame];
        _RegisterTableView.delegate=self;
        _RegisterTableView.dataSource=self;
        
        _RegisterTableView.estimatedRowHeight=60;
        
        _RegisterTableView.tableFooterView=[[UIView alloc]init];
        
        [_RegisterTableView registerNib:[UINib nibWithNibName:@"RegisterSingleTableViewCell" bundle:nil] forCellReuseIdentifier:@"TypeCell1"];
        
        [_RegisterTableView registerNib:[UINib nibWithNibName:@"RegisterPopTableViewCell" bundle:nil] forCellReuseIdentifier:@"TypeCell2"];
        
        [_RegisterTableView registerClass:[RegisterMorePicTableViewCell class] forCellReuseIdentifier:@"TypeCell3"];
        
        [_RegisterTableView registerNib:[UINib nibWithNibName:@"RegisterMoreTextTableViewCell" bundle:nil] forCellReuseIdentifier:@"TypeCell4"];
        
        [_RegisterTableView registerNib:[UINib nibWithNibName:@"RegisterSpicTableViewCell" bundle:nil] forCellReuseIdentifier:@"TypeCell5"];
        
        [_RegisterTableView registerNib:[UINib nibWithNibName:@"ScanCodeTableViewCell" bundle:nil] forCellReuseIdentifier:@"TypeCell6"];
        
        [_RegisterTableView registerNib:[UINib nibWithNibName:@"RegisterTagsTableViewCell" bundle:nil] forCellReuseIdentifier:@"RegistTagsCell"];
        
        [_RegisterTableView registerClass:[RSTableHeadView class] forHeaderFooterViewReuseIdentifier:@"head"];
        
        [self configureNeedShowEmptyDataSetScrollView:_RegisterTableView];
        
    }
    
    return _RegisterTableView;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return self.ShopModel.data.count;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    RSData *Datamodel=self.ShopModel.data[section];
    
    return Datamodel.list.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RSData *Datamodel=self.ShopModel.data[indexPath.section];
    
    RSList *list=Datamodel.list[indexPath.row];
    
    NSLog(@"name = %@ ** type = %zd",list.name,list.fieldType);
    if (list.fieldType==1||list.fieldType==2) {
        
        RegisterSingleTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TypeCell1" forIndexPath:indexPath];
        
        if (list.isVaild) {
            
            cell.TitleName=[NSString stringWithFormat:@"%@*",list.name];
            
        }else{
            
            cell.TitleName=list.name;
        }
        
        if (list.fieldType==2) {
            
            cell.RtextFile.secureTextEntry=YES;
            
        }else{
            
            cell.RtextFile.secureTextEntry=NO;
            
        }
        
        cell.VaildType=list.vaildType;
        
        cell.RtextFile.text=list.value;
        
        [cell.RtextFile removeAllBlocksForControlEvents:UIControlEventEditingChanged];
        
        [cell.RtextFile addBlockForControlEvents:UIControlEventEditingChanged block:^(id  _Nonnull sender) {
            
            UITextField *textf=sender;
            
            list.value=textf.text;
            
        }];
        
        return cell;
        
    }else if (list.fieldType==3||list.fieldType==7||list.fieldType==9)
    {
        
        RegisterPopTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TypeCell2" forIndexPath:indexPath];
        
        if (list.isVaild) {
            
            cell.TitleName=[NSString stringWithFormat:@"%@*",list.name];
            
        }else{
            
            cell.TitleName=list.name;
        }
        
        if (list.fieldType==3) {
            
            NSString *Content=@"";
            
            for (RSItems *item in list.items) {
                
                if ([item.value isEqualToString:list.value]) {
                    
                    Content=item.name;
                    
                    break;
                }
                
            }
            
            cell.RContentLabel.text=Content;
            
        }else{
            
            cell.RContentLabel.text=list.value;
            
        }
        
        
        return cell;
        
    }else if (list.fieldType==5||list.fieldType==12)
    {
        RegisterMorePicTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TypeCell3" forIndexPath:indexPath];
        
        if (list.isVaild) {
            
            cell.TitleName=[NSString stringWithFormat:@"%@*",list.name];
            
        }else{
            
            cell.TitleName=list.name;
        }
        
        cell.isEdit=YES;//是否可编辑
        
        cell.ImageArr=[HelpWay imageStrToArr:list.value];//传递图片数组
        
        TBWeak;
        //删除图片
        cell.delePhoto=^(NSInteger num)
        {
            NSArray *arr=[HelpWay imageStrToArr:list.value];
            
            NSMutableArray *ReArr=[[NSMutableArray alloc]initWithArray:arr];
            
            [ReArr removeObjectAtIndex:num];
            
            NSString*FinalStr=@"";
            
            for (NSString*imageStr in ReArr) {
                
                if (FinalStr.length==0) {
                    
                    FinalStr=imageStr;
                }else{
                    
                    
                    FinalStr=[NSString stringWithFormat:@"%@|%@",FinalStr,imageStr];
                }
                
            }
            
            list.value=FinalStr;
            
            [weakSelf.RegisterTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
            
        };
        
        //浏览图片
        cell.ScanBlock=^(NSInteger num)
        {
            [weakSelf.ScanPhotoArr removeAllObjects];
            
            for (NSString*imagestr in [HelpWay imageStrToArr:list.value]) {
                
                [weakSelf.ScanPhotoArr addObject:[MWPhoto photoWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ReqUrl,imagestr]]]];
                
            }
            
            [weakSelf GoToPhotoScanAndIndex:num];
            
        };
        
        //上传图片
        cell.UploadBlock=^()
        {
            BOOL isScan=NO;
            
            if ([self.postUrl isEqualToString:@"/index.php/FoodCheckApi/ledgerInSimpleAdd.json"]) {
                
                isScan=YES;
            }
            
            [weakSelf GotoLibaraySelectPhotoNum:9 andIsCantainScan:isScan andBlock:^(NSString * armStr) {
                
                if (list.value.length==0) {
                    
                    list.value=armStr;
                    
                }else{
                    
                    list.value=[NSString stringWithFormat:@"%@|%@",list.value,armStr];
                }
                
                [weakSelf.RegisterTableView reloadData];
                
            }];
            
        };
        
        return cell;
        
    }else if (list.fieldType==4){
        
        RegisterSpicTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TypeCell5" forIndexPath:indexPath];
        
        if (list.isVaild) {
            
            cell.TitleName=[NSString stringWithFormat:@"%@*",list.name];
            
        }else{
            
            cell.TitleName=list.name;
        }
        
        if (list.value.length==0) {
            
            cell.IcoImageView.userInteractionEnabled=NO;
            
        }else{
            
            cell.IcoImageView.userInteractionEnabled=YES;
            
            self.headimage=list.value;
            
            UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ShowHEAD)];
            
            [cell.IcoImageView addGestureRecognizer:tap];
            
        }
        
        [cell.IcoImageView LoadWebImageWithName:list.value andIsOrgin:NO];
        
        return cell;
        
    }else if (list.fieldType==8){
        
        ScanCodeTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TypeCell6" forIndexPath:indexPath];
        
        if (list.isVaild) {
            
            cell.TitleLabel.text=[NSString stringWithFormat:@"%@*",list.name];
            
        }else{
            
            cell.TitleLabel.text=list.name;
        }
        
        cell.CodeTextFile.text=list.value;
        
        [cell.CodeTextFile removeAllBlocksForControlEvents:UIControlEventEditingChanged];
        
        [cell.CodeTextFile addBlockForControlEvents:UIControlEventEditingChanged block:^(id  _Nonnull sender) {
            
            UITextField *textf=sender;
            
            list.value=textf.text;
            
        }];
        
        [cell.ScanBtn bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
        
        [cell.ScanBtn bk_addEventHandler:^(id sender) {
            //去扫描
            
            ScanPhotoViewController*scanVC=[ScanPhotoViewController new];
            
            scanVC.Scantype=2;
            
            scanVC.resultBlock=^(NSString *Str)
            {
                
                list.value=Str;
                
                [self.RegisterTableView reloadData];
            };
            
            [self.navigationController pushViewController:scanVC animated:YES];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        return cell;
        
    }else if (list.fieldType == 13){
        
        RegisterTagsTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"RegistTagsCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (list.isVaild) {
            
            cell.titleLab.text=[NSString stringWithFormat:@"%@*",list.name];
        }else{
            
            cell.titleLab.text=list.name;
        }
        cell.baseView.frame = CGRectMake(cell.baseView.frame.origin.x, cell.baseView.frame.origin.y, cell.baseView.frame.size.width, _specTagViewHeigh);
        [cell.baseView addSubview:self.tagsView];
        [self refreshSpecTagView:list];
        
        return cell;
    } else{
        
        RegisterMoreTextTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TypeCell4" forIndexPath:indexPath];
        
        if (list.isVaild) {
            
            cell.TitleName=[NSString stringWithFormat:@"%@*",list.name];
            
        }else{
            
            cell.TitleName=list.name;
        }
        
        cell.RTextView.text=list.value;
        
        cell.VaildType=list.vaildType;
        
        cell.RTextView.delegate=self;
        
        cell.RTextView.tag=indexPath.row+indexPath.section*1000+8000;
        
        return cell;
    }
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RSData *Datamodel=self.ShopModel.data[indexPath.section];
    
    RSList *list=Datamodel.list[indexPath.row];
    
    if (list.fieldType==1||list.fieldType==2||list.fieldType==3||list.fieldType==7||list.fieldType==9) {
        
        return UITableViewAutomaticDimension;
        
    }else if (list.fieldType==6)
    {
        
        return 100;
        
    }else if (list.fieldType==4){
        
        
        return 60;
        
    } else if (list.fieldType==5||list.fieldType==12){
        
        RSData *Datamodel=self.ShopModel.data[indexPath.section];
        
        RSList *list=Datamodel.list[indexPath.row];
        
        NSArray *arr=[HelpWay imageStrToArr:list.value];
        
        NSInteger colorm=arr.count/3+1;//每行放三个，一个有多少行
        
        CGFloat cellHeight=(SCREEN_WIDTH-30-10*2)/3.0;
        
        return 15+10*(colorm-1)+colorm*cellHeight+47;
        
    }else if (list.fieldType==8){
        
        
        return 80;
        
    }else if (list.fieldType == 13)
    {
        return _specTagViewHeigh;
    }
    else{
        return 0;
    }
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 30;
    
}


-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    RSData *Datamodel=self.ShopModel.data[section];
    RSTableHeadView *head=[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"head"];
    
    head.Rtitle=Datamodel.title;
    
    return head;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    RSData *Datamodel=self.ShopModel.data[indexPath.section];
    
    RSList *list=Datamodel.list[indexPath.row];
    
    if (list.fieldType==3) {
        
        //躺框
        ChooseView *chooseView=[[ChooseView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kDevice_Is_iPhoneX?SCREEN_HEIGHT-64-IPhoneXTableHeight:SCREEN_HEIGHT-64) andDataArr:list.items andBlock:^(NSString *value, NSInteger index) {
            
            list.value=value;
            
            [self.RegisterTableView reloadData];
            
        }];
        
        [chooseView PopWithView:self.view];
        
    }else if (list.fieldType==4)
    {
        
        
        //上传图片
        [self GotoLibaraySelectPhotoNum:1 andIsCantainScan:NO andBlock:^(NSString * armStr) {
            
            list.value=armStr;
            
            [self.RegisterTableView reloadData];
            
        }];
        
    }else if (list.fieldType==7)
    {
        //时间选择框
        
        NSDate *date;
        
        if (list.value.length==0) {
            
            date=[NSDate date];
            
        }else{
            
            date=[HelpWay stringToDateWithString:list.value];
            
        }
        
        DatePickView *datePick=[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,kDevice_Is_iPhoneX?SCREEN_HEIGHT-64-IPhoneXTableHeight: SCREEN_HEIGHT-64) andDate:date andblock:^(NSDate *PickDate) {
            
            list.value=[HelpWay dateToStringWith:PickDate];
            
            [self.RegisterTableView reloadData];
            
        }];
        
        [datePick PopWithView:self.view];
        
    }
    
}

-(void)ShowHEAD
{
    [self.ScanPhotoArr removeAllObjects];
    
    [self.ScanPhotoArr addObject:[MWPhoto photoWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ReqUrl,self.headimage]]]];
    
    [self GoToPhotoScanAndIndex:0];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)textViewDidChange:(UITextView *)textView
{
    NSInteger tags=textView.tag;
    
    NSInteger section=(tags-8000)/1000;
    
    NSInteger row=(tags-8000)-section*1000;
    
    RSData *Datamodel=self.ShopModel.data[section];
    
    RSList *list=Datamodel.list[row];
    
    list.value=textView.text;
    
}

#pragma mark-重新刷新页面
- (void)actionTapEmptyDataSetNodataView
{
    [self loadDates];
    
}

-(void)GotoOption:(UIButton*)sender
{
    
    NSMutableDictionary *PostDIC=[NSMutableDictionary dictionary];
    
    for (RSData *data in self.ShopModel.data) {
        
        for (RSList *list in data.list) {
            
            if (list.isVaild) {
                //必填
                if (list.value.length==0) {
                    
                    [MBProgressHUD showWarnMessage:[NSString stringWithFormat:@"%@不能为空",list.name]];
                    
                    return;
                }
                
            }
            
            if (list.value==nil) {
                
                list.value=@"";
            }
            
            if (list.fieldName==nil) {
                
                list.fieldName=@"";
            }
            
            if([list.fieldName isEqualToString:@"welfare"])
            {
//                list.value = self.tagstitles;
                [PostDIC setValue:self.tagsView.selectedTags forKey:list.fieldName];
            }else{
                [PostDIC setValue:list.value forKey:list.fieldName];
            }
        }
        
    }
    
    NSLog(@"%@",PostDIC);
    
    [self showLoadingAnimation];
    
    self.Reqmodel.postData=[HelpWay dictionaryToJSON:PostDIC];
    
    BaseReqApi *Api=[[BaseReqApi alloc]initWithRequestUrl:self.postUrl andrequestTime:5 andParams:self.Reqmodel.mj_keyValues andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:NO];
    
    [Api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
        
        [self stopLoadingAnimation];
        
        if (responseStatus==1) {
            //请求成功
            
            [MBProgressHUD showSuccessMessage:self.OptionSussStr];
            
            if ([self.BtnStr isEqualToString:@"注册"]||[self.BtnStr isEqualToString:@"新增"]) {
                
                _block();
                
                [self.navigationController popViewControllerAnimated:YES];
                
            }else if ([self.BtnStr isEqualToString:@"保存"])
            {
                
                _block();
                
                [self.navigationController popViewControllerAnimated:YES];
                
            }
            
            
        }else if (responseStatus==0||responseStatus==2)
        {
            [MBProgressHUD showErrorMessage:message];
            
        }
        
    }];
}

#pragma mark **************** 福利标签 ****************
//选择标签视图的高度
- (void)getTagsViewHeigh
{
    RSList *itemlist = [RSList new];
    
    for (RSData *data in self.ShopModel.data) {
        
        for (RSList *list in data.list) {
            
            if ([list.name isEqualToString:@"福利"]) {
                itemlist = list;
                
                if(list.items.count >0)
                {
                    NSMutableArray *tagsArray = [NSMutableArray array];
                    [tagsArray addObjectsFromArray:list.items];
                    
                    NSArray *titles = [self gettitleArray:tagsArray];
                    
                    CGFloat tagsHeight = 0;
                    if(titles.count)
                    {
                        tagsHeight = [HXTagsView getHeightWithTags:titles layout:nil tagAttribute:nil width:kScreenWidth-100];
                    }
                    CGFloat tagviewH   = tagsHeight + (list.items.count >0?10:0);
                    
                    _specTagViewHeigh = tagviewH>60?(tagviewH+10):60;
                }
            }
        }
    }
}
//刷新标签视图
- (void)refreshSpecTagView:(RSList*)list
{
    NSMutableArray *tagsArray = [NSMutableArray array];
    [tagsArray addObjectsFromArray:list.items];
    
    self.tagsView.tags = [self gettitleArray:tagsArray];
    if(self.tagsView.tags.count)
    {
        self.tagsView.height = [HXTagsView getHeightWithTags:self.tagsView.tags layout:self.tagsView.layout tagAttribute:self.tagsView.tagAttribute width:kScreenWidth-100];
        [self.tagsView reloadData];
    }
}

- (NSArray *)gettitleArray:(NSArray*)tagsArray
{
    NSMutableArray *tagstitleArray = [NSMutableArray array];
    [self.tagsView.selectedTags removeAllObjects];
    
    for(int i =0 ;i<tagsArray.count;i++)
    {
        RSItems *item = tagsArray[i];
        if(item.selected == 1)
        {
            self.tagsView.selectTitle = item.name;
            [self.tagsView.selectedTags addObject:item.name];
        }
        [tagstitleArray addObject:item.name];
    }
    
    return tagstitleArray;
}
- (HXTagsView*)tagsView
{
    if(_tagsView == nil)
    {
        _tagsView = [[HXTagsView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth-100, _specTagViewHeigh)];
        _tagsView.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _tagsView.isMultiSelect = YES;
        _tagsView.completion = ^(NSArray *selectTags,NSInteger currentIndex) {
            
        };
    }
    return _tagsView;
}
- (NSMutableArray*)tagstitles
{
    if(_tagstitles == nil)
    {
        _tagstitles = [NSMutableArray array];
    }
    return _tagstitles;
}
@end
